<?php

class DatabaseSeeder extends Seeder {

	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		Eloquent::unguard();

		$this->call('PageTemplatesSeeder');
		$this->call('ProductCategorySeeder');
		$this->call('ProductSeeder');
		$this->call('UserSeeder');
		$this->call('PageSeeder');
		$this->call('ProductImageFileTypeSeeder');
	}

}

class PageTemplatesSeeder extends Seeder
{
	public function run()
	{
		// Add page templates
		App\Models\PageTemplate::create(array(
			"name"=>"home",
			"title"=>"Homepage Template"
		));

		App\Models\PageTemplate::create(array(
			"name"=>"internal",
			"title"=>"Internal Template"
		));
	}
}

class ProductCategorySeeder extends Seeder
{
	public function run()
	{
		// Add page templates
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"diy",
			"slug"=>"diy-products",
			"title"=>"DIY Products"
		));

		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"specifiers",
			"slug"=>"specifier-products",
			"title"=>"Specifier Products"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"trade",
			"slug"=>"trade-products",
			"title"=>"Trade Products"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"bagged-concrete",
			"slug"=>"bagged-concrete-products",
			"title"=>"Bagged Concrete"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"tiling",
			"slug"=>"tiling-products",
			"title"=>"Tiling"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"flooring",
			"slug"=>"flooring-products",
			"title"=>"Flooring"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"waterproofing",
			"slug"=>"waterproofing-products",
			"title"=>"Waterproofing"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"admixtures",
			"slug"=>"admixtures-products",
			"title"=>"Admixtures"
		));
		
		App\Models\ProductCategory::create(array(
			"parentid"=>0,
			"name"=>"sealing-coating",
			"slug"=>"sealing-coating-products",
			"title"=>"Sealing / Coating"
		));

	}
}

class ProductSeeder extends Seeder
{
	public function run()
	{
		// Add products
		App\Models\Product::create(array(
			"categoryid"=>1,
			"name"=>"product1",
			"slug"=>"product1",
			"shortdescription"=>"product1",
			"description"=>"product1"
		));

		App\Models\Product::create(array(
			"categoryid"=>2,
			"name"=>"product2",
			"slug"=>"product2",
			"shortdescription"=>"product2",
			"description"=>"product2"
		));

		App\Models\Product::create(array(
			"categoryid"=>3,
			"name"=>"product3",
			"slug"=>"product3",
			"shortdescription"=>"product3",
			"description"=>"product3"
		));

		App\Models\Product::create(array(
			"categoryid"=>4,
			"name"=>"product4",
			"slug"=>"product4",
			"shortdescription"=>"product4",
			"description"=>"product4"
		));

		App\Models\Product::create(array(
			"categoryid"=>5,
			"name"=>"product5",
			"slug"=>"product5",
			"shortdescription"=>"product5",
			"description"=>"product5"
		));

		

	}
}

class UserSeeder extends Seeder
{
	public function run()
	{
		DB::table('users')->delete();
        DB::table('groups')->delete();
        DB::table('users_groups')->delete();
 
        Sentry::getUserProvider()->create(array(
            'email'       => 'arkson82@gmail.com',
            'password'    => "anand",
            'first_name'  => 'Anand',
            'last_name'   => 'Kulkarni',
            'activated'   => 1,
        ));

        Sentry::getUserProvider()->create(array(
            'email'       => 'marketing@cemix.co.nz',
            'password'    => "mktg1519",
            'first_name'  => 'Cemix',
            'last_name'   => 'Marketing',
            'activated'   => 1,
        ));
 
        Sentry::getGroupProvider()->create(array(
            'name'        => 'Admin',
            'permissions' => array('admin' => 1),
        ));
 
        // Assign user permissions
        $adminUser  = Sentry::getUserProvider()->findByLogin('arkson82@gmail.com');
        $adminGroup = Sentry::getGroupProvider()->findByName('Admin');
        $adminUser->addGroup($adminGroup);

        $adminUser  = Sentry::getUserProvider()->findByLogin('marketing@cemix.co.nz');
        $adminGroup = Sentry::getGroupProvider()->findByName('Admin');
        $adminUser->addGroup($adminGroup);
	}
}

class PageSeeder extends Seeder
{
	public function run()
	{
		DB::table('pages')->delete();
 
        App\Models\Page::create(array(
            'parentid'=> 0,
            'pagetemplateid' => 1,
            'is_homepage' => true,
            'pageorder' => 1,
            'name'   => 'Home',
            'slug'    => 'home',
            'title'   => 'Home',
            'content'    => 'Lorem ipsum dolor sit amet.'
        ));

        App\Models\Page::create(array(
            'parentid'=> 0,
            'pagetemplateid' => 1,
            'is_homepage' => false,
            'pageorder' => 1,
            'name'   => 'Page 1',
            'slug'    => 'page-1',
            'title'   => 'Page 1',
            'content'    => 'Lorem ipsum dolor sit amet.'
        ));

        App\Models\Page::create(array(
            'parentid'=> 0,
            'pagetemplateid' => 1,
            'is_homepage' => false,
            'pageorder' => 1,
            'name'   => 'Page 2',
            'slug'    => 'page-2',
            'title'   => 'Page 2',
            'content'    => 'Lorem ipsum dolor sit amet.'
        ));

        App\Models\Page::create(array(
            'parentid'=> 2,
            'pagetemplateid' => 1,
            'is_homepage' => false,
            'pageorder' => 1,
            'name'   => 'Page 1.1',
            'slug'    => 'page-1-1',
            'title'   => 'Page 1.1',
            'content'    => 'Lorem ipsum dolor sit amet.'
        ));

        App\Models\Page::create(array(
            'parentid'=> 2,
            'pagetemplateid' => 1,
            'is_homepage' => false,
            'pageorder' => 1,
            'name'   => 'Page 1.2',
            'slug'    => 'page-1-2',
            'title'   => 'Page 1.2',
            'content'    => 'Lorem ipsum dolor sit amet.'
        ));
	}
}

class ProductImageFileTypeSeeder extends Seeder
{
	public function run()
	{
		App\Models\ProductImageType::create(array("type"=>"Main"));
		App\Models\ProductImageType::create(array("type"=>"Additional"));
		App\Models\ProductImageType::create(array("type"=>"Case Study"));

		App\Models\ProductFileType::create(array("type"=>"MSDS"));
		App\Models\ProductFileType::create(array("type"=>"Brochure"));
		App\Models\ProductFileType::create(array("type"=>"Datasheet"));
		App\Models\ProductFileType::create(array("type"=>"CAD Drawing"));
		App\Models\ProductFileType::create(array("type"=>"ZIP Download"));
	}
	
}